
Security News
High Salaries No Longer Enough to Attract Top Cybersecurity Talent
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
@gasket/request
Advanced tools
The purpose of this package is to provide a consistent request object for Gasket plugins and apps to use, regardless of the request handling framework.
npm install @gasket/request
The GasketRequest
class is a representation of a request object that can be
used by Gasket plugins and apps. It is a consistent shape that can be used
across different request handling frameworks.
A GasketRequest
object has the following properties:
Property | Type | Description | Arguments |
---|---|---|---|
headers | object | Request headers | required |
cookies | object | Request cookies | default: {} |
query | object | Query parameters | default: {} |
path | string | Request path | default: '' |
A GasketRequest
can be created from a Node IncomingMessage
object, an
Express Request
object, or a Next.js NextRequest
object, amongst others.
import { makeGasketRequest } from '@gasket/request';
export default async function expressHandler(req, res) {
const gasketRequest = await makeGasketRequest(req);
// use gasketRequest
}
You can also assemble a GasketRequest
object from parts of a request object.
import { makeGasketRequest } from '@gasket/request';
const headers = {
'x-example': 'example'
};
const staticGasketRequest = await makeGasketRequest({ headers });
A higher-order function that can wrap a GasketAction function and provides a
GasketRequest
object as the first argument.
This provides an easy way to normalize the request object for any GasketAction
and potential lifecycle hooks.
import { withGasketRequest } from '@gasket/request';
export const myAction = withGasketRequest(
async function handler(gasket, gasketRequest) {
// use gasketRequest
}
);
// example usage
await gasket.actions.myAction(req);
If your action needs additional arguments, you can pass them following the gasketReq
.
import { withGasketRequest } from '@gasket/request';
export const myAction = withGasketRequest(
async function handler(gasket, gasketRequest, arg1, arg2) {
// use gasketRequest
}
);
// example usage
await gasket.actions.myAction(req, true, false);
Much like the previous function, withGasketRequestCache
is a higher-order
function that wraps an action handler function and provides a GasketRequest
.
The difference is the handler will only be triggered once per request, and the
result will be cached for subsequent calls.
import { withGasketRequestCache } from '@gasket/request';
export const myAction = withGasketRequestCache(
async function handler(gasketRequest, req, arg1, arg2) {
// use gasketRequest
}
);
// example usage
await gasket.actions.myAction(req, true, false);
Why do we need a request object for Gasket?
Some Gasket plugins and apps need to interact with the request object. Unfortunately, the shape and details of a request object is not consistent across all request handling frameworks.
For example:
IncomingMessage
docsRequest
docs
NextRequest
docsRequest
docsAnd we are aware of apps using Gasket for Static Pages with Next.js, assembling a request-like object to use with certain actions.
FAQs
Utilities for working with request objects in Gasket
The npm package @gasket/request receives a total of 190 weekly downloads. As such, @gasket/request popularity was classified as not popular.
We found that @gasket/request demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Product
Socket, the leader in open source security, is now available on Google Cloud Marketplace for simplified procurement and enhanced protection against supply chain attacks.
Security News
Corepack will be phased out from future Node.js releases following a TSC vote.